package org.dydl.controller.system;

import java.util.Random;

import org.dydl.common.dto.ResponseMessage;
import org.dydl.model.system.Production;
import org.dydl.model.system.vo.ProductionDetailVO;
import org.dydl.model.system.vo.RegisterVO;
import org.dydl.service.system.ProduceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 生产任务单接口
 * @author 张华城
 *
 */
@RestController
@RequestMapping("/api/produce")
public class ProduceController{

	@Autowired
	private ProduceService produceService;
	

	/**
	 * 根据订单号查询生产任务
	 * @param orderNo
	 * @return
	 */
	@RequestMapping("/list")
	public ResponseMessage list(@RequestParam(value = "orderNo", required = false)String orderNo){
		
		return produceService.list(orderNo);
	}
	
	/**
	 * 获取生产任务单列表
	 * @param page
	 * @param rows
	 * @param productionNo
	 * @return
	 */
	@RequestMapping("/getList")
	public ResponseMessage getList(int page,int rows ,String productionNo){
		
		return produceService.getList(page, rows, productionNo);
	}
	

	/**
	 * 下达生产任务
	 * @param detailVO
	 * @return
	 */
	@RequestMapping("/save")
	public ResponseMessage bothSave(@RequestBody ProductionDetailVO detailVO){
		
		return produceService.bothSave(detailVO);	
		
	}
	
	/**
	 * 保存表头
	 * @param production
	 * @return
	 */
	@RequestMapping("/saveProduction")
	public ResponseMessage saveProduction(@RequestBody Production production){
		return produceService.save(production);
	}
	
	/**
	 * 根据订单号查询生产任务明细列表
	 * @param page
	 * @param rows
	 * @param orderNo
	 * @return
	 */
	@RequestMapping("/getDetailList")
	public ResponseMessage getDetailList(int page,int rows,String orderNo){
		
				
		return produceService.getDetailList(page, rows, orderNo);
	}
	
	@RequestMapping("/getStowageList")
	public ResponseMessage getStowageList(){
		
		return produceService.getStowageList();
	}
	
	/**
	 * 根据订单号查询所需物料列表
	 * @param orderNo
	 * @return
	 */
	@RequestMapping("/getLoss")
	public ResponseMessage getLoss(String orderNo){
		
		
		return produceService.getLoss(orderNo);
	}
	/**
	 * 成品入库登记
	 * @param request
	 */
	@RequestMapping("/doRegister")
	public ResponseMessage doRegister(@RequestBody RegisterVO registerVO){
		return produceService.doRegister(registerVO);
	}
	
	/**
	 * 审核
	 * @param id
	 */
	@RequestMapping("/doExamination")
	public ResponseMessage doExamination(@RequestParam(value = "ids", required = false)Integer ids,Production production){
		
		return produceService.doExamination(ids,production);
		
	}
	@RequestMapping("/complete")
	public ResponseMessage complete(Integer id){
		
		return produceService.complete(id);
	}
	
	/**
	 * 生成生产单号
	 * @return
	 */
	@RequestMapping("/getProductionNo")
	public String getBomNo(){
		Random random = new Random();
		int ran = random.nextInt(89)+10;
		return "A"+(System.currentTimeMillis())+""+ran;	
	}
	
}
